class SRFire extends KFFire;

var const float DamageStaminaExpenceRate;
var bool bSilentWeapon,bSaboteurWeap;
var float InvisExpence;

event ModeDoFire()
{
	local float Rec;

	if (!AllowFire())
		return;
		
	SRHumanPawn(Instigator).ConsumeStamina(WeaponStaminaCost());

	if( Instigator==None || Instigator.Controller==none )
		return;

    Spread = GetSpread();

	Rec = GetFireSpeed();
	FireRate = default.FireRate/Rec;
	FireAnimRate = default.FireAnimRate*Rec;
	ReloadAnimRate = default.ReloadAnimRate*Rec;
	Rec = 1;

	if ( KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo) != none && KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo).ClientVeteranSkill != none )
	{
		Spread *= KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo).ClientVeteranSkill.Static.ModifyRecoilSpread(KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo), self, Rec);
	}

	LastFireTime = Level.TimeSeconds;

	if (Weapon.Owner != none && AllowFire() && !bFiringDoesntAffectMovement)
	{
		if ( bSaboteurWeap && SRPlayerReplicationInfo(Instigator.PlayerReplicationInfo).ClientVeteranSkill.default.PerkIndex == class'SRVetSaboteur'.default.PerkIndex )
		{
			Weapon.Owner.Velocity.x *= 1.09;
			Weapon.Owner.Velocity.y *= 1.09;
		}
		else if (FireRate > 0.25)
		{
			Weapon.Owner.Velocity.x *= 0.1;
			Weapon.Owner.Velocity.y *= 0.1;
		}
		else
		{
			Weapon.Owner.Velocity.x *= 0.5;
			Weapon.Owner.Velocity.y *= 0.5;
		}
	}

	Super(InstantFire).ModeDoFire();

    // client
    if (Instigator.IsLocallyControlled())
    {
        if( bDoClientRagdollShotFX && Weapon.Level.NetMode == NM_Client )
        {
            DoClientOnlyFireEffect();
        }
        HandleRecoil(Rec);
    }
}

function DoFireEffect()
{
    local Vector StartTrace;
    local Rotator R, Aim;

	if ( !bSilentWeapon /*|| !SRPlayerReplicationInfo(Instigator.PlayerReplicationInfo).bInvisible*/ )
	{
		Instigator.MakeNoise(1.0);
		if ( SRHumanPawn(Instigator).bInvisible )
		{
			SRHumanPawn(Instigator).BecomeVisible();
		}
	}
	else
	{
		if ( SRHumanPawn(Instigator).bInvisible )
		{
			//DKGameType(Level.Game).ConsumeInvis(SRHumanPawn(Instigator).InvisController,InvisExpence);
		}
	}

    // the to-hit trace always starts right in front of the eye
    StartTrace = Instigator.Location + Instigator.EyePosition();
    Aim = AdjustAim(StartTrace, AimError);
	R = rotator(vector(Aim) + VRand()*FRand()*Spread);
    DoTrace(StartTrace, R);
}

function float WeaponStaminaCost()
{
	local KFWeapon KFW;
	local float ExpenceMod;
	
	KFW = KFWeapon(Weapon);
	
	if ( KFW == none )
		return 0.0;
		
	ExpenceMod = 1.0;
	if ( Thompson(KFW) != none || SA80LSW(KFW) != none || PKM(KFW) != none || M249Machinegun(KFW) != none )
	{
		ExpenceMod *= 1.0 + ( 1.0 - class<KFWeaponDamageType>(DamageType).default.HeadShotDamageMult ) * 0.5;
	}
	else
	{
		ExpenceMod *= class<KFWeaponDamageType>(DamageType).default.HeadShotDamageMult;
	}

	ExpenceMod *= class'SRVeterancy'.Static.AddDamage(SRPlayerReplicationInfo(Instigator.Controller.PlayerReplicationInfo),none,none,10000,DamageType) * 0.0001;
	
	if ( Thompson(KFW) != none || SA80LSW(KFW) != none || PKM(KFW) != none || M249Machinegun(KFW) != none || Deagle(KFW) != none || Winchester1_(KFW) != none
		|| DualDeagle(KFW) != none || MK23Pistol(KFW) != none || DualMK23Pistol(KFW) != none || Bal_Magnum44Pistol(KFW) != none || Bal_Dual44Magnum(KFW) != none )
	{
		ExpenceMod *= 1.4;
	}

	if ( ThisModeNum == 0 )
	{
		return DamageMax * ExpenceMod * DamageStaminaExpenceRate;
	}
	
	// ThisModeNum == 1, Our next actions ===>
	
	if ( Single(KFW) != none || Dualies(KFW) != none || Shotgun1_(KFW) != none /*|| Bal_BenelliShotgun(KFW) != none*/ )
	{
		return 0.5;
	}
	
	return 0.0;
}

defaultproperties
{
	DamageStaminaExpenceRate = 0.002;
	InvisExpence = 0.00;
	bSilentWeapon = false;
}
